from core.basehandler import BaseHandler
from core.room import Room
from core.action import Action
from core.support import set_cutscene
from items.needle import Needle
from rooms.victory_room import VictoryRoom

class RecordPlayer(Room):
    def __init__(self, room_id):
        Room.__init__(self, room_id)    # do basic initialization for every room
        self.tookNeedle = False
        # add inventory items
        #ADD A RECORD PLAYER NEEDLE HERE
        #ADD A JOHNNY CASH RECORD HERE
        
        # build list of actions
        self.add_action(StandUp)
        self.add_action(TakeNeedle)
        self.add_action(PlayRecord)
    
    # return description of room.
    def get_description(self):
        return "MacGyver bends down to look closely at the record as it spins.  The needle looks to be loosely attached."
    
    # return image of room
    def get_image(self):
        return 'recordplayer.jpg'


class RecordPlayerHandler(BaseHandler):
    
    # return class to use to create a new instance of this room
    def get_room_class(self):
        return RecordPlayer

# define actions for this room

class StandUp(Action):
    def __init__(self):
        Action.__init__(self, "StandUp")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Stand Up"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        return 'wardensoffice'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"
    
class TakeNeedle(Action):
    def __init__(self):
        Action.__init__(self, "take_needle")    # do basic initialization for every action
        
    # this method gets called when action executed.  can be overridden in subclass
    def do_action(self,game,room,request):
        if game.get_player().can_pickup():
            room.tookNeedle = True
            game.get_player().add_item(Needle())
            set_cutscene("MacGyver snaps the needle off of the record player.")
        return
    
    # should this action be available to player?
    def is_enabled(self):
        return not self.room.tookNeedle
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Break off needle"
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"

class PlayRecord(Action):
    def __init__(self):
        Action.__init__(self, "play_record")    # do basic initialization for every action
        
    def do_action(self,game,room,request):
        game.get_room('victory_room',VictoryRoom).set_image('JCash.jpg')
        game.get_room('victory_room',VictoryRoom).set_description("Folsom Prison Blues blares through the speaker... a dozen guards rush to the Warden's Office and apprehend MacGyver. Game Over.")
        game.get_room('victory_room',VictoryRoom).set_audio('Cash.mp3')
        return
    
    # should this action be available to player?
    def is_enabled(self):
        return not self.room.tookNeedle
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Play Record Player"
    
    def get_destination(self):
        return "victory_room"
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"

